package br.com.edoc.aop;

import java.lang.reflect.Method;

import org.springframework.aop.ThrowsAdvice;

import br.com.edoc.excecoes.ExceptionApplication;
import br.com.edoc.gerentes.GerentePadraoImpl;

public class AdivisorSaveOrUpdateThrowException implements ThrowsAdvice {
	public void afterThrowing(Method method, Object[] args, Object target,
			ExceptionApplication runtimeException) {
		if(((GerentePadraoImpl) target).getTransacao().isActive()){
			((GerentePadraoImpl) target).rowback();
			System.out.println("RollBack comitada");
		}
		
		if(((GerentePadraoImpl) target).getSession().isOpen()){
			((GerentePadraoImpl)target).close();
			System.out.println("Conexão Fechada");
		}

	}
}
